package com.bruce.tool.map.gaode.web.to;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Optional;

/**
 * @author Bruce(刘正航)
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PointResult {
    private Integer status;
    private String infocode;
    private List<ResultInfo> geocodes;

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ResultInfo {
        private String province;
        private String city;
        private String district;
        private String formattedAddress;
        /**
         * 坐标
         */
        private String location;

        public Point getLocation() {
            return Optional.ofNullable(location).map(item -> {
                String[] split = location.split(",");
                return Point.builder()
                        .lat(Double.parseDouble(split[0]))
                        .lng(Double.parseDouble(split[1]))
                        .build();
            }).orElse(null);
        }
    }

    public boolean isSucess() {
        return "10000".equals(this.infocode);
    }
}
